package com.ygo.feihua.fragment;
import android.support.v4.app.*;
import android.os.*;
import android.view.*;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;

import android.graphics.*;
import com.ygo.feihua.*;
import com.ygo.feihua.BmobTable.*;
import android.util.*;
import com.ashokvarma.bottomnavigation.BadgeItem;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.qnw.CardGroupManagement.*;

public class MainBottomBarFragment extends Fragment 
{
	private BottomNavigationBar main_bottom_navigation_bar;

	private FragmentManager fragmentManager;
	private FragmentMain mainFragment;
	private FragmentBankuai bankuaiFragment;
	private FragmentShezhi shezhiFmt;
	private WoGuanyu guanyuFmt;
	private CgmaZhuye cgmaZhuye;
	private Fragment dqFragment;

	public void ParsingDeck(String img_url)
	{
		cgmaZhuye.ParsingDeck(img_url);
		// TODO: Implement this method
	}

	
	
	public TieType getShequType()
	{
		// TODO: Implement this method
		return mainFragment.getShequType();
	}

	public void shequSettingLongClick()
	{
		mainFragment.shequSettingLongClick();
		// TODO: Implement this method
	}

	public void shequSettingClick()
	{
		mainFragment.shequSettingClick();
		// TODO: Implement this method
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View v=inflater.inflate(R.layout.fragment_main_bottom_bar,null);
		main_bottom_navigation_bar = (BottomNavigationBar) v.findViewById(R.id.main_bottom_navigation_bar);
		
		mainFragment=new FragmentMain();
		bankuaiFragment=new FragmentBankuai();
		shezhiFmt=new FragmentShezhi();
		guanyuFmt=new WoGuanyu();
		cgmaZhuye=new CgmaZhuye();
		
		main_bottom_navigation_bar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {//这里也可以使用SimpleOnTabSelectedListener
				@Override
				public void onTabSelected(int position) {//未选中 -> 选中
					Log.e("MaimBottomBarFragment","值为"+position);
					FragmentTransaction transaction = fragmentManager.beginTransaction();
					Fragment f3=null;//fragmentManager.getFragments().get(position);
					switch(position){
						case 0:
							f3=mainFragment;
							((CeHua)getActivity()).setToolMain();
							break;
						case 1:
							f3=bankuaiFragment;
							((CeHua)getActivity()).setToolOurygo();
							break;
						case 2:
							f3=cgmaZhuye;
							((CeHua)getActivity()).setToolDeck();
							break;
						case 3:
							f3=shezhiFmt;
							((CeHua)getActivity()).setToolOurygo();
							break;
						case 4:
							f3=guanyuFmt;
							((CeHua)getActivity()).setToolOurygo();
							break;
					}

					if (!f3.isAdded()) {
						// 先判断是否被add过
						transaction.hide(dqFragment).add(R.id.main_flcon, f3).commit(); // 隐藏当前的fragment，add下一个到Activity中
					} else {
						transaction.hide(dqFragment).show(f3).commit(); // 隐藏当前的fragment，显示下一个
					}

					dqFragment=f3;
				}

				@Override
				public void onTabUnselected(int position) {//选中 -> 未选中
					Log.e("MaimBottomBarFragment","onTabUnselected值为"+position);
				}

				@Override
				public void onTabReselected(int position) {//选中 -> 选中
					Log.e("MaimBottomBarFragment","onTabReselected值为"+position);
				}
			});
		BadgeItem badgeItem = new BadgeItem().setBackgroundColor(Color.RED).setText("new");
		main_bottom_navigation_bar.setMode(BottomNavigationBar.MODE_SHIFTING);
		main_bottom_navigation_bar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
		main_bottom_navigation_bar.setBarBackgroundColor(R.color.colorVice);
		
		main_bottom_navigation_bar.addItem(new BottomNavigationItem(R.drawable.ic_home, "主页").setActiveColorResource(R.color.activeColorResource).setInActiveColorResource(R.color.white))
			.addItem(new BottomNavigationItem(R.drawable.ic_page_list_selector, "板块").setActiveColorResource(R.color.activeColorResource).setInActiveColorResource(R.color.white))//.setBadgeItem(badgeItem))
			.addItem(new BottomNavigationItem(R.drawable.it_kz, "卡组").setActiveColorResource(R.color.activeColorResource).setInActiveColorResource(R.color.white))
			.addItem(new BottomNavigationItem(R.drawable.ic_settings, "设置").setActiveColorResource(R.color.activeColorResource).setInActiveColorResource(R.color.white))
			.addItem(new BottomNavigationItem(R.drawable.ic_guanyu, "关于").setActiveColorResource(R.color.activeColorResource).setInActiveColorResource(R.color.white))
			.setFirstSelectedPosition(0)
			.initialise(); //所有的设置需在调用该方法前完成

		
		
		setDefaultFragment();
		
		// TODO: Implement this method
		return v;
	}
	
    // 设置默认的
    private void setDefaultFragment() {
        fragmentManager =getFragmentManager();
		dqFragment=mainFragment;
        fragmentManager.beginTransaction().add(R.id.main_flcon, dqFragment).commit();
		
    }
	
}
